﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Geotools.Geometries;
using AzukiMap.Tools;

namespace AzukiMap.Map
{
    public delegate void MapExtentChangedHandler(object sender, MapExtentChangedArgs e);
    public delegate void MapScaleChangedHandler(object sender, MapScaleChangedArgs e);
    public delegate void MapProjectionChangedHandler(object sender, MapProjectionChangedArgs e);
    public delegate void MapRotationChangedHandler(object sender, MapRotationChangedArgs e);
    public delegate void MouseMovedHandler(object sender, MouseMovedArgs e);

    public partial class MapControl
    {
        public event MapExtentChangedHandler MapExtentChanged;
        public event MapScaleChangedHandler MapScaleChanged;
        public event MapProjectionChangedHandler MapProjectionChanged;
        public event MapRotationChangedHandler MapRotationChanged;
        public event MouseMovedHandler MouseMoved;

        protected virtual void OnMapExtentChanged(MapExtentChangedArgs e)
        {
            if (MapExtentChanged != null)
            {
                MapExtentChanged(this, e);
            }
        }

        protected virtual void OnMapScaleChanged(MapScaleChangedArgs e)
        {
            if (MapScaleChanged != null)
            {
                MapScaleChanged(this, e);
            }
        }

        protected virtual void OnMapProjectionChanged(MapProjectionChangedArgs e)
        {
            if (MapProjectionChanged != null)
            {
                MapProjectionChanged(this, e);
            }
        }

        protected virtual void OnMapRotationChanged(MapRotationChangedArgs e)
        {
            if (MapRotationChanged != null)
            {
                MapRotationChanged(this, e);
            }
        }

        protected virtual void OnMouseMoved(MouseMovedArgs e)
        {
            if (MouseMoved != null)
            {
                MouseMoved(this, e);
            }
        }
    }

    public class MapExtentChangedArgs : EventArgs
    {
        GTPolygon _extent = null;

        public MapExtentChangedArgs(GTPolygon extent)
        {
            _extent = extent;
        }

        public double[] Extent
        {
            get
            {
                GeometryUtil geomUtil = new GeometryUtil();
                double[] extentArr = geomUtil.GetExtentPointsArr(_extent);
                return extentArr;
            }
        }

    }

    public class MapScaleChangedArgs : EventArgs
    {
        double _screenScale;
        double _geoScale;

        public MapScaleChangedArgs(double geoScale, double screenScale)
        {
            _geoScale = geoScale;
            _screenScale = screenScale;
        }

        public double Scale
        {
            get { return _geoScale; }
        }

        public double ScreenScale
        {
            get { return _screenScale; }
        }

    }

    public class MapProjectionChangedArgs : EventArgs
    {
        int _srid;

        public int Srid
        {
            get { return _srid; }
        }

        public MapProjectionChangedArgs(int srid)
        {
            _srid = srid;
        }

    }

    public class MapRotationChangedArgs : EventArgs
    {
        double _angle;

        public double Angle
        {
            get { return _angle; }
        }

        public MapRotationChangedArgs(double angle)
        {
            _angle = angle;
        }
    }

    public class MouseMovedArgs : EventArgs
    {
        GTPoint _geoPoint;
        Point _mousePoint;

        public GTPoint GeoPoint
        {
            get { return _geoPoint; }
            set { _geoPoint = value; }
        }

        public Point MousePoint
        {
            get { return _mousePoint; }
            set { _mousePoint = value; }
        }

        public MouseMovedArgs(GTPoint geoPoint, Point mousePoint)
        {
            _geoPoint = geoPoint;
            _mousePoint = mousePoint;
        }
    }

}
